#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    void pc(const char *s){
    	while(*s)putch(*s),s++;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=2e5+5,mod=1e9+7;
inline int Mod(int x){return x>=mod?x-mod:x;}
int n;
int P[N];
vector<int>to[N];
int s[N],siz[N],len[N],son[N];
struct node{
	int s0,s1,s2;
	friend node operator +(node A,node B){
		B.s0=Mod(B.s0+B.s2);
		return node{1ll*A.s0*B.s0%mod,(1ll*A.s0*B.s1+1ll*A.s1*B.s0)%mod,(1ll*A.s1*B.s1+1ll*A.s2*Mod(B.s0+B.s1))%mod};
	}
}f[N];
void dfs1(int x,int dep){
	len[x]=1;
	s[dep]++;
	siz[x]=1;
	for(auto y:to[x]){
		dfs1(y,dep+1);
		siz[x]+=siz[y];
		len[x]=max(len[x],len[y]+1);
		if(son[x]==0)son[x]=y;
		else if(len[y]>len[son[x]])son[x]=y;
	}
}
void dfs2(int x,node *g){
	g[0]={1,1,0};
	if(son[x])dfs2(son[x],g+1);
	else return;
	int maxn=0;
	for(auto y:to[x]){
		if(y==son[x])continue;
		maxn=max(maxn,len[y]);
	}
	for(int i=1;i<=maxn;i++)g[i].s0=Mod(g[i].s0+g[i].s2),g[i].s2=0;
	int tot=siz[son[x]]+1;
	for(auto y:to[x]){
		if(y==son[x])continue;
		node *h=g+tot;tot+=siz[y];
		dfs2(y,h);
		for(int i=0;i<len[y];i++)
			g[1+i]=g[1+i]+h[i];
	}
}
signed main(){
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	read(n);
	for(int i=P[0]=1;i<=n;i++)P[i]=Mod(P[i-1]+P[i-1]);
	for(int i=1;i<=n;i++){
		int x;read(x);
		to[x].push_back(i); 
	}
	dfs1(0,0),dfs2(0,f);
	int ans=0;
	for(int i=0;i<len[0];i++)
		ans=Mod(ans+1ll*P[n+1-s[i]]*f[i].s1%mod);
	write(ans);
	return flush(),0;
}
/*
5
0 1 0 0 4

*/

